#### Buildings as points Approx. 30 seconds per batch. Approx. 4.5 GB.# Read exposure as table, with point geometries tn = 'economic_exposure_gob_gar15' fn = f'{root}/economic_exposure_gob_gar15.parquet' # Create table with geometries con.sql(f""" DROP TABLE IF EXISTS {tn}; CREATE TABLE {tn} AS SELECT *, ST_GeomFromText(geom_point) AS geom -- Convert geometry column from WKT to DuckDB geometry type FROM read_parquet('{fn}'); """) # Create directory to store .gpkg batches dir_points = f'{root}/gob_gar15_points' os.makedirs(dir_points, exist_ok=True) # Get the total number of rows in the table row_count = con.sql(f"SELECT COUNT(*) FROM {tn}").fetchone()[0] # Set batch size batch_size = 100000 batches = math.ceil(row_count / batch_size) # Avoid extra batch if row_count % batch_size == 0 # Export in chunks for i in range(batches): offset = i * batch_size chunk_fn = f"{dir_points}/economic_exposure_gob_gar15_point_part{i + 1}.gpkg" # Use dir_points print(f"Exporting batch {i + 1}/{batches}...") con.sql(f""" COPY ( SELECT * FROM {tn} LIMIT {batch_size} OFFSET {offset} ) TO '{chunk_fn}' WITH (FORMAT GDAL, DRIVER 'GPKG'); """) print(f"Batch {i + 1} completed.")
# Define tags for public infrastructure (extensive inventory) infrastructure_tags = { "aeroway": ["aerodrome"], "amenity": ["library", "research_institute", "school", "university", "bus_station", "clinic", "hospital", "community_centre", "social_centre", "courthouse", "fire_station", "police", "post_office", "prison", "townhall", "fuel", "marketplace", "place_of_worship" ], "building": ["religious", "bridge", "civic", "college", "fire_station", "government", "hospital", "public", "school", "train_station", "transportation", "university", "sports_hall", "sports_centre", "stadium", "transformer_tower", "water_tower", "military" ], "highway": ["motorway", "trunk", "primary", "secondary", "tertiary", "unclassified", "road" "bus_stop" ], "historic": ["archaeological_site", "building", "monument"], "man_made": ["bridge", "communications_tower", "dyke", "embankment", "pipeline", "wastewater_plant"], "office": ["administrative", "government"], "power": ["line", "plant", "substation"], "public_transport": ["station", "stop_position", "platform"], "railway": ["station", "stop"], "tourism": ["attraction", "museum"], "waterway": ["dam", "weir"] }